#include "project_config.h"

#if (CMD_TIMER_TEST == 1)
#include "qelib.h"



static void cmd_timer_start(const char *name, int ms)
{
    qe_timer_dev *timer = (qe_timer_dev *)qe_dev_find(name);
    if (!timer) {
        qe_printf("%s not found\r\n", name);
        return;
    }

    qe_timer_start(timer, ms);

    qe_printf("%s start %d\r\n", name, ms);
}
QE_SHELL_EXPORT_CMD_FUNC(2, tmrstart, cmd_timer_start, start timer <name> <ms>);

static void cmd_timer_elapsed(const char *name)
{
    qe_timer_dev *timer = (qe_timer_dev *)qe_dev_find(name);
    if (!timer) {
        qe_printf("%s not found\r\n", name);
        return;
    }

    qe_u32 elapsed = qe_timer_elapsed(timer);

    qe_printf("elapsed:%dus\r\n", elapsed);
}
QE_SHELL_EXPORT_CMD_FUNC(1, tmrelapsed, cmd_timer_elapsed, get timer elapsed);

static void cmd_timer_stop(const char *name)
{
    qe_timer_dev *timer = (qe_timer_dev *)qe_dev_find(name);
    if (!timer) {
        qe_printf("%s not found\r\n", name);
        return;
    }

    qe_timer_stop(timer);

    qe_printf("%s stop\r\n", name);
}
QE_SHELL_EXPORT_CMD_FUNC(1, tmrstop, cmd_timer_stop, stop timer);

static void timer_cb(void *args)
{
    qe_printf("tiemr cb\r\n");
}

static void cmd_timer_cb(const char *name)
{
    qe_timer_dev *timer = (qe_timer_dev *)qe_dev_find(name);
    if (!timer) {
        qe_printf("%s not found\r\n", name);
        return;
    }

    qe_timer_set_callback(timer, timer_cb, QE_NULL);
}
QE_SHELL_EXPORT_CMD_FUNC(1, tmrcb, cmd_timer_cb, set timer callback);
#endif